/*
  ID: nemokin1
  PROG: milk2
  LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef long double ld;
const int INF = 1000000000;

int main() {
    //freopen("milk2.in","r",stdin); freopen("milk2.out","w",stdout);
    int N,a,b;
    cin >> N;
    vector<pair<int,int> > vp;
    REP(i,N){
	cin >> a >> b;
	vp.push_back(make_pair(a,b));
    }
    sort(ALL(vp));
    int mm1 = 0,mm2 = 0;
    int ret1 = 0, ret2 = 0;
    int line = vp[0].first;

    FOREACH(it,vp){
	if(it->first <= line){
	    if(it->second-line >= 0)
		mm1+=it->second-line;
	    checkMax(ret1,mm1);
	}
	else{
	    mm1 = it->second - it->first;
	    mm2 = it->first - line;
	    if(mm2 < 0) mm2 = 0;
	    checkMax(ret2,mm2);
	}
	line = max(line,it->second);
    }
    cout<<ret1<<" "<<ret2<<endl;
    exit(0);
}
